from pydantic import BaseModel
from typing import Optional
from datetime import datetime

class UserCreate(BaseModel):    # 用户注册/创建时输入的验证
    username: str
    password: str
    is_admin: bool = False                  # 默认非管理员用户

class UserLogin(BaseModel):     # 用户登录时输入的验证
    username: str
    password: str

class UserOut(BaseModel):       # 用户信息输出模型（隐藏敏感字段如密码）
    id: int
    username: str
    is_admin: bool

    class Config:
        from_attributes = True

class MeetingCreate(BaseModel):
    title: str
    # 新增结构化字段（可选）
    meeting_time: Optional[str] = None
    location: Optional[str] = None
    participants: Optional[str] = None
    minutes: Optional[str] = None
    todos: Optional[str] = None
    # 保留 content 字段以兼容旧客户端，允许 JSON 字符串或纯文本
    content: Optional[str] = None

class MeetingOut(BaseModel):
    id: int
    title: str
    content: Optional[str]
    meeting_time: Optional[str] = None
    location: Optional[str] = None
    participants: Optional[str] = None
    minutes: Optional[str] = None
    todos: Optional[str] = None
    created_by: int
    created_at: datetime

    class Config:
        from_attributes = True


class ResourceCreate(BaseModel):
    core_point: str
    source: Optional[str] = None
    material_type: Optional[str] = None
    category: Optional[str] = None
    note: Optional[str] = None
    video_link: Optional[str] = None


class ResourceOut(BaseModel):
    id: int
    core_point: str
    source: Optional[str]
    material_type: Optional[str]
    category: Optional[str]
    note: Optional[str]
    attachments: Optional[str]
    video_link: Optional[str]
    created_by: int
    created_at: datetime

    class Config:
        from_attributes = True
